package com.ophiux.cs.application.consultBase.impl;

import com.ophiux.cs.application.consultBase.dto.GetDoctorRequest;
import com.ophiux.cs.application.consultBase.dto.GetDoctorResponse;
import com.ophiux.cs.application.consultBase.service.IGetDoctorAppService;
import com.ophiux.cs.application.core.AppResultCode;
import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.application.core.ResultEnum;
import com.ophiux.cs.domain.consultBase.model.entity.Doctor;
import com.ophiux.cs.domain.consultBase.model.valueobj.DoctorQueryObj;
import com.ophiux.cs.domain.consultBase.repositories.IDoctorRepository;
import com.ophiux.utils.common.ShiftUtils;
import com.ophiux.utils.exception.OphiuxRepositoryException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class GetDoctorAppService implements IGetDoctorAppService {

    @Autowired
    IDoctorRepository doctorRepositories;


    @Override
    public Result<GetDoctorResponse> getDoctor(GetDoctorRequest dto) {
        GetDoctorResponse resp = new GetDoctorResponse();
        //验证参数是否允许为空
        if(!dto.isParamValid()) {
            return Result.fail(ResultEnum.requestParamFail.getCode(), ResultEnum.requestParamFail.getMsg());
        }
        try {
            DoctorQueryObj doc = null;
            doc = (DoctorQueryObj) ShiftUtils.objToNewObj(dto, DoctorQueryObj.class);
            try {
                List<Doctor> docList=doctorRepositories.selectDoctor();
                resp.setDocList(docList);
            } catch (OphiuxRepositoryException e) {
                e.printStackTrace();
                return Result.fail(ResultEnum.requestException.getCode(), e.getExceptionMessage());
            }
        } catch (Exception e) {
            log.info("getDoctor接口异常：",e);
            e.printStackTrace();
            return Result.fail(AppResultCode.EXCEPTION, "程序异常");
        }
        return Result.success(resp, "查询医生成功");
    }
}
